let userLoginNumber = document.getElementById("userLoginNumber")
let registUser = document.getElementById("registUser")

userLoginNumber.addEventListener("click", (event) => {
    document.location = "./home.html"

})
registUser.addEventListener("click", (event) => {
    document.location = "./UserRegister.html"

})
userLoginNumber.addEventListener("mouseenter", (event) => {
    event.target.style.color = "#FFFFFF"
    event.target.style.cursor = "pointer"
})
userLoginNumber.addEventListener("mouseleave", (event) => {
    event.target.style.color = "#CCCCCC"

})

let userLoginButton = document.getElementById("userLoginButton")
let checkManagerIDAndPassword = function (id, pwd) {
    return true;

}

userLoginButton.addEventListener("click", () => {
    let userID = document.getElementById("userID").value
    let userPassword = document.getElementById("userPassword").value
    if (checkManagerIDAndPassword()) {
        $.post("/pub/userLogin",
            {

                id: userID,
                password: userPassword

            },
            function (res) {
                if (res.status.startsWith("4")) {

                    document.getElementById("loginInformation").innerText = res.message
                } else {
                    Cookies.set('id', res.data.id, { expires: 1 })
                    Cookies.set('username', res.data.username, { expires: 1 })
                    alert(`sign in success,${Cookies.get('username')}`)
                    document.location = "/public/html/UserDashboard.html"
                }
            }, "json");
    } else {
        document.getElementById("loginInformation").innerText = "user ID or password invalid"
    }


})
